<?php

namespace App\Admin\Controllers;

use App\Admin\Repositories\FourAdminMessage;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;

class FourAdminMessageController extends AdminController
{
    /**
     * Make a grid builder.
     *列表页
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new FourAdminMessage(), function (Grid $grid) {
            //标题模糊查询
            $grid->quickSearch('title');
            $grid->column('title','通知标题');
            $grid->column('content','内容');
            $grid->column('send_name','上传者');
            $grid->column('send_time','上传时间');
            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');
            });
            //关闭查看详情
//            $grid->actions(function (Grid\Displayers\Actions $actions) {
//                $actions->disableView();
//            });
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *详情页
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new FourAdminMessage(), function (Show $show) {
//            $msm=\App\Models\FourAdminMessage::find($id)->status;
            $show->field('id');
            $show->field('title','通知标题');
            $show->field('content','内容');
            $show->field('send_name','上传者');
            $show->status('是否启用')->using(['0'=>'未启用','1'=>'已启用']);
            $show->field('send_time','上传时间');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *添加，编辑页
     * @return Form
     */
    protected function form()
    {
        return Form::make(new FourAdminMessage(), function (Form $form) {
            $form->display('id');
            $form->text('title','通知标题');
            //富文本
            $form->editor('content','内容');
            $form->text('send_name','上传者');
            //开关
            $form->switch('status','是否启用')
                ->customFormat(function ($v) {
                    return $v == '1' ? 1 : 0;
                })
                ->saving(function ($v) {
                    return $v ? '1' : '0';
                });
            $form->datetime('send_time','上传时间');
            $form->display('created_at');
            $form->display('updated_at');
        });
    }
}
